package org.example.predicate;

import com.alibaba.fastjson.JSONObject;

import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class Java8PredicateInObject {
    public static void main(String[] args) {
        Hosting h1 = new Hosting(1, "amazon", "aws.amazon.com");
        Hosting h2 = new Hosting(2, "linode", "linode.com");
        Hosting h3 = new Hosting(3, "liquidweb", "liquidweb.com");
        Hosting h4 = new Hosting(4, "google", "google.com");

        List<Hosting> hostings = Arrays.asList(h1,h2,h3,h4);
        List<Hosting> result = HostingRepository.filterHosting(hostings, new Predicate<Hosting>() {
            @Override
            public boolean test(Hosting hosting) {
                return hosting.getName().startsWith("g");
            }
        });
        System.err.println(JSONObject.toJSONString(result));

        List<Hosting> result2 = HostingRepository.filterHosting(hostings,isDeveloperFriendly());
        System.err.println(JSONObject.toJSONString(result2));

    }

    static Predicate<Hosting> isDeveloperFriendly(){
        return n -> n.getName().equals("linode");
    }
}

